
proc freq data=actoren;
 tables agencygroup*grouptype/nocol nopercent nocum out=committee outpct; /* proportion per category */
 where DVdummy eq 1;

proc transpose data=committee out=committee prefix=p_; by agencygroup; id grouptype; var pct_row;

/* mergen */
data committee; merge committee; 

array zero a_p_experts p_nonbusiness p_otherbusine p_regbusiness p_publicautho;
 do _i_ = 1 to 5;
 if zero eq . then zero = 0;
 end;

/* transform percentages in proportions */
array prop p_experts p_nonbusiness p_otherbusine p_regbusiness p_publicautho; 
 do _i_ = 1 to 5;
 prop = prop/100;
 end;

/* calculate HHI */
array hhi1   p_experts p_nonbusiness p_otherbusine p_regbusiness p_publicautho; 
array hhi2   hexperts  hnonbusiness  hotherbusine  hregbusiness  hpublicautho ; 
 do _i_ = 1 to 5;
 hhi2=hhi1*hhi1;
 end;

hhi=sum(hexperts,hnonbusiness,hotherbusine,hregbusiness,hpublicautho);

run;

proc print data=committee;
 var agencygroup hhi;
run;
